package com.leoandroid.tool.toolsbox.new

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.leoandroid.tool.toolsbox.largeread.databinding.ActivityJitangBinding
import com.leoandroid.tool.toolsbox.net.NetCallBack
import com.leoandroid.tool.toolsbox.net.NetRequest
import org.json.JSONObject
import java.text.SimpleDateFormat
import java.util.*

class JiTangActivity : AppCompatActivity() {

    var bindingF: ActivityJitangBinding? = null
    val binding get() = bindingF!!

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        bindingF = ActivityJitangBinding.inflate(layoutInflater)
        setContentView(binding.root)
        binding.includeTitle.titleTv.text = "每日一句"
        binding.includeTitle.backIv.setOnClickListener {
            finish()
        }
        binding.monthTv.text = SimpleDateFormat("yyyy-MM").format(System.currentTimeMillis())
        val calendar: Calendar = Calendar.getInstance()
        binding.xingqiTv.text = com.leoandroid.tool.toolsbox.utils.DateUtils.getWeek(System.currentTimeMillis())
        binding.dayTv.text = calendar.get(Calendar.DAY_OF_MONTH).toString()

        val url = "https://apis.juhe.cn/fapig/soup/query?key=cddeda97b93ec253a5c90ab538422874"
        NetRequest.asyncGet(url, object : NetCallBack {

            override fun onFailure(code: Int, e: Throwable?) {

            }

            override fun onSuccess(json: JSONObject?) {
                val string = json?.getString("result")
                val jsonResult = JSONObject(string)
                val textStr = jsonResult.getString("text")
                runOnUiThread {
                    binding.textview.text = textStr
                }
            }

        })
    }
}